/**
@author - Gyanendra Singh/ Suresh Chandra Pal
@version - 1.0 28/Feb/2009
**/
function loadPage(page) {
	changeImageCursor(page);
	changeColorCursor(page);
	loadContent(page);
	return false;
}

function loadModule(page) {
	changeColorCursor2(page);
	loadContent(page);
	return false;
}

function loadPage(page, params) {	
	changeImageCursor(page);
	changeColorCursor(page);
	loadContent(page, params);
	return false;
}

function showLoadPage() {
	document.getElementById("holder").innerHTML = '';	
}

/**
Method used to toggle between the arrow image
**/
function changeImageCursor(imgName) {
	var navTabs = document.getElementById("tabs"); 
	if(navTabs != null) {
		var selImage = navTabs.getElementsByTagName("img");		
		var i;
	   	
	   	for(i = 0; i < selImage.length; i++) {  
	   		var imgSrc = selImage[i].src; 	
	   		var matchResult = imgSrc.match("rightarrow");
	   		
	   		if(!matchResult)
	   			continue;
	   		var test2 = selImage[i].name;
	   		if(selImage[i].name == imgName) {
	       		selImage[i].style.visibility = 'visible';
	    	} else {
	       		selImage[i].style.visibility = 'hidden';
	    	}
	   }
	}	
}

/**
Method used to toggle between the color of selected items
**/
function changeColorCursor(divName) {
	var navTabs = document.getElementById("tabs");  
	if(navTabs != null) {
		var selDiv = navTabs.getElementsByTagName("div");		
		var i;
	   	selectedDivID = divName;
	   	for(i = 0; i < selDiv.length; i++) { 
	   		var divValue = selDiv[i].id; 
	   		if(divValue == divName) {
	       		colorChangeOnSelection(divName);
	    	} else {
	       		colorChangeUnDo(divValue);
	    	}
	   	}	
	}
}

function changeColorCursor2(divName) {
	var navTabs = document.getElementById("menu_id");  
	if(navTabs != null) {
		var selDiv = navTabs.getElementsByTagName("td");		
		var i;
	   	selectedDivID = divName;
	   	for(i = 0; i < selDiv.length; i++) { 
	   		var divValue = selDiv[i].id; 
	   		if(divValue == divName) {
	       		colorChangeOnSelection(divName);
	    	} else {
	       		colorChangeUnDo(divValue);
	    	}
	   	}	
	}
}


function loadContent(page) {
	var params = null;
	loadContent(page, params);
}

function loadContent(page, params) {
	
	var serverUrl = "../jsp/" + page + ".jsp";
	createRequest();
	
	if(ajaxRequest == null)
		return;
	
	searchManager(page);
	
	ajaxRequest.onreadystatechange = function() { paintContent(); };
	ajaxRequest.open("POST", serverUrl, true);
	ajaxRequest.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	ajaxRequest.send(params);
	return false;	
}

function paintContent() {
	
	if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
		showProgressBar(0);	
		document.getElementById("holder").innerHTML = ajaxRequest.responseText;	    
	} else {		
		showProgressBar(1);		
	}
}

/*
Method used to change the color of the top menu button on the mouseover & out.
*/
function colorChangeOnSelection(id) {
	document.getElementById(id).style.backgroundColor = mainHeaderChangeBkgColor; 
	document.getElementById(id).style.color = mainHeaderSelectFontColor;
}

function colorChangeTemporary(id) {
	if(selectedDivID != id) {
		/*
		document.getElementById(id).style.backgroundColor = mainHeaderChangeBkgColor; 
		document.getElementById(id).style.color = mainHeaderChangeFontColor;
		*/
		document.getElementById(id).style.background = mainHeaderChangeBkgColor; 
		document.getElementById(id).style.color = mainHeaderChangeFontColor;
		
	}
	
}

function colorChangeUnDo(id) {
	if(selectedDivID != id) {
		document.getElementById(id).style.background = mainHeaderBkgColor; 
		document.getElementById(id).style.color = mainHeaderFontColor;
	}
}

function showProgressBar(sw) {
	if (sw == 1) {
		// Show popup
		if(document.getElementById('blackoutProgress') != null)
			document.getElementById('blackoutProgress').style.visibility = 'visible';
		if(document.getElementById('divpopupProgress') != null)
			document.getElementById('divpopupProgress').style.visibility = 'visible';
		if(document.getElementById('blackoutProgress') != null)
			document.getElementById('blackoutProgress').style.display = 'block';
		if(document.getElementById('divpopupProgress') != null)
			document.getElementById('divpopupProgress').style.display = 'block';
	} else {
	
		// Hide popup
		if(document.getElementById('blackoutProgress') != null)
			document.getElementById('blackoutProgress').style.visibility = 'hidden';
		if(document.getElementById('divpopupProgress') != null)
			document.getElementById('divpopupProgress').style.visibility = 'hidden';
		if(document.getElementById('blackoutProgress') != null)
			document.getElementById('blackoutProgress').style.display = 'none';
		if(document.getElementById('divpopupProgress') != null)
			document.getElementById('divpopupProgress').style.display = 'none';
	}
}

function searchManager(page) {
	if( (searchablePages.match(currentPage) == null) || currentPage != page) {
		if(document.getElementById("searchValue") != null) {
			document.getElementById("searchValue").value = searchTextValue;
		}
		previousSearch = "";
	}
	
	currentPage = page;
}

